/*
 * Created by JFormDesigner on Thu Sep 09 20:09:46 CST 2021
 */

package com.minelx.woods.pc.form;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.minelx.woods.pc.form.values.VariantValues;

import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.stream.Collectors;
import javax.swing.*;
import javax.swing.border.*;

/**
 * @author aaa
 */
public class ViewVariantCollectionsDialog extends JDialog {
	public ViewVariantCollectionsDialog(Window owner, JSONArray variantCollections) {
		super(owner, "", ModalityType.APPLICATION_MODAL);
		initComponents();

		List<String> names = variantCollections.toJavaList(JSONObject.class).stream()
				.map(variantCollectionAsJSON -> variantCollectionAsJSON.getString("name") + ", 参数为: " + variantCollectionAsJSON.getJSONObject("variables").toJSONString())
				.collect(Collectors.toList());
		DefaultListModel<String> variantCollectionsListModel = new DefaultListModel<>();
		variantCollectionsListModel.addAll(names);
		variantCollectionsList.setModel(variantCollectionsListModel);
	}

	private void okButtonActionPerformed(ActionEvent e) {
		dispose();
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		dialogPane = new JPanel();
		contentPanel = new JPanel();
		label2 = new JLabel();
		variantCollectionsList = new JList<>();
		buttonBar = new JPanel();
		okButton = new JButton();

		//======== this ========
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		var contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		//======== dialogPane ========
		{
			dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
			dialogPane.setLayout(new BorderLayout());

			//======== contentPanel ========
			{
				contentPanel.setLayout(new BorderLayout());

				//---- label2 ----
				label2.setText("\u53d8\u91cf\u5b57\u6bb5");
				label2.setFont(new Font("Microsoft JhengHei Light", Font.PLAIN, 30));
				contentPanel.add(label2, BorderLayout.NORTH);

				//---- variantCollectionsList ----
				variantCollectionsList.setFont(new Font("Microsoft JhengHei Light", Font.PLAIN, 22));
				contentPanel.add(variantCollectionsList, BorderLayout.CENTER);
			}
			dialogPane.add(contentPanel, BorderLayout.CENTER);

			//======== buttonBar ========
			{
				buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
				buttonBar.setLayout(new FlowLayout(FlowLayout.TRAILING, 5, 0));

				//---- okButton ----
				okButton.setText("OK, \u8fd8\u53ef\u4ee5");
				okButton.setFont(new Font("Microsoft JhengHei Light", Font.PLAIN, 22));
				okButton.addActionListener(e -> okButtonActionPerformed(e));
				buttonBar.add(okButton);
			}
			dialogPane.add(buttonBar, BorderLayout.SOUTH);
		}
		contentPane.add(dialogPane, BorderLayout.CENTER);
		setSize(695, 585);
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	private JPanel dialogPane;
	private JPanel contentPanel;
	private JLabel label2;
	private JList<String> variantCollectionsList;
	private JPanel buttonBar;
	private JButton okButton;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
}
